package com.frejoys.store.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.aop.VerifyStore;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.common.IdDto;
import com.frejoys.common.dto.store.ChangeSortDto;
import com.frejoys.common.dto.store.StoreCategorySaveDto;
import com.frejoys.common.dto.store.StoreCategoryUpdateDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.util.RequestUtil;
import com.frejoys.common.vo.store.StoreCategoryVo;
import com.frejoys.service.StoreCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "店铺类目", description = "店铺类目管理")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixStore)
@Authorization(Authority.Private)
public class MallStoreCategoryController {

    private final StoreCategoryService storeCategoryService;

    /**
     * 根据店铺id获取店铺所有类目
     */
    @Operation(summary = "根据店铺id获取店铺所有类目")
    @PostMapping("/storeCategory/listStoreCategory")
    public Result<List<StoreCategoryVo>> listStoreCategory(@RequestBody @Validated IdDto dto){
        return Result.success(storeCategoryService.listStoreCategory(dto.getId()));
    }


    /**
     * 新增店铺类目
     */
    @VerifyStore
    @Operation(summary = "新增店铺类目")
    @PostMapping("/storeCategory/addInfo")
    public Result addInfo(@RequestBody @Validated StoreCategorySaveDto dto){
        storeCategoryService.addInfo(dto);
        return Result.success();
    }

    /**
     * 修改店铺类目
     */
    @VerifyStore
    @Operation(summary = "修改店铺类目")
    @PostMapping("/storeCategory/upInfo")
    public Result upInfo(@RequestBody @Validated StoreCategoryUpdateDto dto){
        storeCategoryService.upInfo(dto);
        return Result.success();
    }

    /**
     * 修改店铺类目
     */
    @VerifyStore
    @Operation(summary = "删除店铺类目")
    @PostMapping("/storeCategory/delInfo")
    public Result delInfo(@RequestBody @Validated IdDto dto){
        storeCategoryService.delInfo(dto, RequestUtil.userId());
        return Result.success();
    }

    /**
     * 修改品类顺序
     */
    @VerifyStore
    @Operation(summary = "修改品类顺序")
    @PostMapping("/storeCategory/changeSort")
    public Result changeSort(@RequestBody @Validated List<ChangeSortDto> dtos){
        storeCategoryService.changeSort(dtos);
        return Result.success();
    }
}
